<div>
    <div class="col-lg-12">
        <section class="panel">
            <div class="panel-body">
                <form class="form-horizontal adminex-form" onsubmit="return false;">
                    <div class="base">
                        <div class="base-left">
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="red-start">*</span> 登录账号</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" name="account" placeholder="请输入登录账号" value="<?php echo $this->detail['account']?>"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="red-start">*</span> 员工姓名</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" name="name" placeholder="请输入员工姓名" value="<?php echo $this->detail['name']?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">手机</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" name="tel" placeholder="请输入手机" value="<?php echo $this->detail['tel']?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">Email</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" name="email" placeholder="请输入Email" value="<?php echo $this->detail['email']?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">角色</label>
                                <div class="col-sm-4">
                                    <select name="role"  id='role' class="form-control">
                                        <option value="1" <?php echo $this->detail['enterprise_role_id'] == 1 ? 'checked' : '';?>>管理员</option>
                                        <option value="2" <?php echo $this->detail['enterprise_role_id'] == 2 ? 'checked' : '';?>>业务员</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div style="clear: both"></div>
                    <div style="margin-top: 50px;"></div>
                    <input type="hidden" value="<?php echo $this->detail['id']?>" id="edit_id">
                    <div class="form-group">
                        <div class="modal-footer" style="text-align: left;margin-left: 6%;">
                            <button class="btn btn-success" type="button"  onclick="sureSave()">保存</button>
                            <button class="btn btn-success" type="button" style="background-color:#CCCCCC;border-color:#CCCCCC;" data-dismiss="modal" aria-hidden="true">
                                <a href="#" onclick="window.history.back()" style="text-decoration: none;">取消</a></button>
                        </div>
                    </div>
                </form>
            </div>
        </section>
    </div>
</div>
<script type="text/javascript">
    //提交表单
    function sureSave(){
        var account = $("input[name='account']").val();
        var name = $("input[name='name']").val();
        var tel = $("input[name='tel']").val();
        var email = $("input[name='email']").val();
        var role = $("#role").val();
        var id = $("#edit_id").val();

        if(!account){
            layer.alert('请填写登录账号');
            return false;
        }
        if(!name){
            layer.alert('请填写员工姓名');
            return false;
        }
        if(tel){
            var tel_patter = /^1[3|4|5|7|8]{1}\d{9}$/;
            if (!tel_patter.test(tel)) {
                layer.alert('手机号码不规范！');
                return false;
            }

        }
        if(email){
            var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (!filter.test(email)){
                layer.alert('邮箱格式不正确！');
                return false;
            }
        }
        var index = layer.msg('保存中...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,offset: '0px', time:1000000});

        $.ajax({
            url  : '/setting/staff-edit',
            type : 'get',
            data : {
                account:account,
                name:name,
                tel:tel,
                email:email,
                role:role,
                id:id,
                type:'edit'
            },
            dataType : 'json',
            success : function (msg) {
                if (msg.code == 200) {
                    layer.close(index);
                    layer.alert('保存成功',function () {
                        location.href = '/setting/staff-list';
                    })
                } else{
                    layer.close(index);
                    layer.alert('保存失败');
                }
            }
        });
    }
</script>